from sqlalchemy import Column, Integer, String, orm

from app.models.base import Base, db
class Mock(Base):
    id = Column(Integer, primary_key=True)
    function_name=Column(String(1000),unique=False, nullable=False) #mock实现的功能
    request_data=Column(String(1000),unique=True, nullable=False) #请求参数，不可为空，不能重复
    return_data=Column(String(1000),unique=False, nullable=False) #返回参数

    @orm.reconstructor
    def __init__(self):
        self.fields = ['id', 'request_data', 'return_data', 'create_time']

    @staticmethod
    def add_mock(function_name,request_data,return_data):
        with db.auto_commit():
            mock = Mock()
            mock.function_name = function_name
            mock.request_data = request_data
            mock.return_data = return_data
            db.session.add(mock)
    @staticmethod
    def update_mock(mock,function_name,request_data, return_data):
            mock.function_name=function_name
            mock.request_data = request_data
            mock.return_data = return_data
            db.session.commit()

    @staticmethod
    def del_mock(mock):
        mock.del_status=0
        db.session.commit()